#include "globalobserver.h"
#include <aknglobalnote.h>
#include <avkon.rsg>
#include <avkon.hrh>
#include "mtalog.h"

CGlobalNote* CGlobalNote::NewL()
{
	CGlobalNote *self = new(ELeave)CGlobalNote(CEikonEnv::Static());
	CleanupStack::PushL(self);
	self->ConstructL();
	CleanupStack::Pop(self);
	return self;
}

CGlobalNote:: CGlobalNote(CEikonEnv* aEnv): CActive(0), iEnv(aEnv)
{	
}

void CGlobalNote::ConstructL()
{
	CActiveScheduler::Add(this);
}

CGlobalNote::~CGlobalNote()
{
	Cancel();
	if(iNote)
	{
		delete iNote;
		iNote = 0;
	}
}

void CGlobalNote::ShowGlobalNoteL()
{
	iNote = CAknGlobalNote::NewL();
	
	iStatus = KRequestPending;
	SetActive();  // Starting GlobalNoteMonitor to capture yes/no key event.

	_LIT(KGlobalNoteMsg, "Already captured events will be lost. Do you want to continue?");
	TBuf<120> globalNoteMsg;
	globalNoteMsg.Zero();
	globalNoteMsg.Append(KGlobalNoteMsg);

	iNote->SetSoftkeys(R_AVKON_SOFTKEYS_YES_NO);
	iNote->ShowNoteL(iStatus, EAknGlobalInformationNote, globalNoteMsg);
}

void CGlobalNote::RunL() 
{
	if(iStatus.Int() == 3005) // YES
	{
		CAutoTester* autoTester = CAutoTester::GetInstance();
		autoTester->ReloadEvents();
	}
	else if(iStatus.Int() == 3006) // No
	{
		LOGTXT("No Need to reload events from file!");
	}
	delete iNote;
	iNote = 0;
}

void CGlobalNote::DoCancel()
{

}
